﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class QuanTri_TrangDanhSachLop : System.Web.UI.Page
{
    SoLienLacDataContext db = new SoLienLacDataContext();
    clsLoadCombobox cls = new clsLoadCombobox();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] == null || Session["Username"].ToString() == "")
        {
            Response.Redirect("~/GiaoDienClient/TrangChu.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                cls.LoadComboboxNamHoc(drNamHoc);
                int manam = int.Parse(drNamHoc.SelectedValue.ToString());
                LoadKhoi10(manam);
                LoadKhoi11(manam);
                LoadKhoi12(manam);
            }
        }
    }
    protected void drNamHoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        int manam = int.Parse(drNamHoc.SelectedValue.ToString());
        LoadKhoi10(manam);
        LoadKhoi11(manam);
        LoadKhoi12(manam);
    }
    private void LoadKhoi10(int manam)
    {
        var c = from i in
                    (from p in db.Lop_HocSinhs
                     where p.LopHoc.MaKhoi == 1 && p.MaNam == manam
                     select new { p.MaLop, p.LopHoc.TenLop })
                group i by new { i.MaLop, i.TenLop } into grp
                select new { grp.Key.MaLop,grp.Key.TenLop};
        grvKhoi10.DataSource = c;
        grvKhoi10.DataBind();
    }
    private void LoadKhoi11(int manam)
    {
        var c = from i in
                    (from p in db.Lop_HocSinhs
                     where p.LopHoc.MaKhoi == 2 && p.MaNam == manam
                     select new { p.MaLop, p.LopHoc.TenLop })
                group i by new { i.MaLop, i.TenLop } into grp
                select new { grp.Key.MaLop, grp.Key.TenLop };
        grvKhoi11.DataSource = c;
        grvKhoi11.DataBind();
    }
    private void LoadKhoi12(int manam)
    {
        var c = from i in
                    (from p in db.Lop_HocSinhs
                     where p.LopHoc.MaKhoi == 3 && p.MaNam == manam
                     select new { p.MaLop, p.LopHoc.TenLop })
                group i by new { i.MaLop, i.TenLop } into grp
                select new { grp.Key.MaLop, grp.Key.TenLop };
        grvKhoi12.DataSource = c;
        grvKhoi12.DataBind();
    }
}